<?php


namespace app\admin\validate\admin;
use think\validate;

class Admin extends Validate
{



    protected $rule =   [

        'username'  => ['require', 'length' =>'3,16' , 'unique'=>'admin'],
        //'password'=>['require','confirm','length'=>'6,16','regex'=>'/(?!^(\d+|[a-zA-Z]+|[~!@#$%^&*()_.]+)$)^[\w~!@#$%^&*()_.]{8,16}$/'],
        'password'=>['require','confirm','length'=>'6,16'],
    ];

    protected $message  =   [

        'username.require'      => ['code' => 4012, 'msg' => '用户名不能为空'],
        'username.unique'      => ['code' => 4013, 'msg' => '用户名已经存在'],
        'username.length'      => ['code' => 4014, 'msg' => '用户名长度是3到16位'],
        'password.confirm'   => ['code' => 4015, 'msg' => '二次密码不一致'],
        'password.require'   => ['code' => 4015, 'msg' => '密码不能为空'],
        'password.length'    => ['code' => 4016, 'msg' => '密码至少6-16位'],
    ];

    // edit 验证场景定义
    public function sceneModify()
    {
        return $this->remove('password',true);
    }

    // edit 验证场景定义
    public function scenePassword()
    {
        return $this->only(['password']);

    }

    // login 验证场景定义
    public function sceneLogin()
    {
        return $this->only(['username','password'])
            ->remove(['username'=>'unique','password'=>'confirm']);


    }


}